package com.tjetc.controller;

import com.tjetc.common.JsonResult;
import com.tjetc.entity.Employee;
import com.tjetc.service.EmployeeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("employee")
public class EmployeeController {
    @Autowired
    private EmployeeService employeeService;

    @RequestMapping("detail/{employeeId}")
    public JsonResult detail(@PathVariable("employeeId") Long id) {
        return employeeService.findById(id);
    }
    @RequestMapping("page")
    public JsonResult page(@RequestParam(value = "name", required = false,defaultValue = "") String name,
                           @RequestParam(value = "pageNo",required = false,defaultValue = "1") Integer pageNo,
                           @RequestParam(value = "pageSize",required = false,defaultValue = "2") Integer pageSize) {
        return employeeService.findPage(name,pageNo,pageSize);
    }
    @RequestMapping("delete/{employeeId}")
    public JsonResult delete(@PathVariable("employeeId") Long id) {
      return employeeService.deleteById(id);
    }
    //接收参数格式是json
    @RequestMapping("save")
    public JsonResult save(@RequestBody Employee employee){
        return employeeService.save(employee);
    }
}
